#ifndef SYMTABLE_
#define SYMTABLE_
#include <vector>
#include <string>
using namespace std;

typedef enum TYPE_ {
    NOT_SPECIFIED=0,
    T_INT=1,
    T_FLOAT=2,
    T_ARR=4,
    T_INT_ARR=5,
    T_FLOAT_ARR=6,
    T_STRUCT=8,
    T_STRUCT_ARR=12,
    T_FUNCTION,
    T_ERR,
    T_BOOL,
    T_NUM_INT,
    T_NUM_FLOAT
} Type;
enum ChkType {
    C_VAR,
    C_FUNC,
    C_STRU
};
struct Specifier
{
    Type type;
    string name;
    int line;
};

//定义的基础类，包括定义的行号等
struct DefBase
{
    string name;
    Type type;
    int lineno;
    int offset;
    string struct_name;
    DefBase(){
        struct_name="";
        offset=0;
    }
};
//数组类型
struct Array:virtual DefBase
{
    int dimen;
    vector<int> sizes;
    Array(){dimen=0;type=NOT_SPECIFIED;}
};
//原始类型
struct Struct;
struct Primitive : virtual DefBase
{
    union {
        int ival;
        float fval;
    };
    Primitive(){type=NOT_SPECIFIED;ival=fval=0;}
    Primitive(Specifier s,string var_name,int off){
        type=s.type;
        offset=off;
        name=var_name;
        lineno=s.line;
        struct_name=s.name;
    }
};
//结构体域
struct StructField:Primitive,Array{
    StructField(Specifier s,Array a){
        type=Type(s.type|a.type);
        lineno=a.lineno;
        name=a.name;
        if(s.type==T_STRUCT)
            struct_name=s.name;
        if(a.type==T_ARR)
        {
            dimen=a.dimen;
            sizes=a.sizes;
        }
    }
};
//结构体类型
struct Struct : DefBase
{
    vector<StructField> fields;
    int size;
    Struct():size(0){}
};
//函数定义
struct Function : DefBase
{
    int param_offset;
    Type return_type;
    string return_struct_name;
    vector<Array> params;
};
struct Field
{
    vector<Primitive> primitives;
    vector<Array> arrays;
};
struct Return {
    Type type;
    int line;
};

#endif